package com.android.multiplesmart.utils;


import com.android.multiplesmart.activity.BaseActivity;

import java.util.Stack;

/**
 * @author zhangzhiguo
 * @date 2019-08-05 09:39
 * @Description: 定义的Activity栈工具类
 */

public class ActivityUtils {
    private static Stack<BaseActivity> mActivityStack;

    /**
     * 添加一个Activity到堆栈中
     * @param activity
     */
    public static void addActivity(BaseActivity activity) {
        if (null == mActivityStack) {
            mActivityStack = new Stack<>();
        }
        mActivityStack.add(activity);
    }


    public static Stack<BaseActivity> getAllActivity() {
        return mActivityStack;
    }



    /**
     * 从堆栈中移除指定的Activity
     * @param activity
     */
    public static void removeActivity(BaseActivity activity) {
        if (activity != null) {
            mActivityStack.remove(activity);
        }
    }

    /**
     * 获取顶部的Activity
     * @return 顶部的Activity
     */
    public static BaseActivity getTopActivity() {
        if (mActivityStack.isEmpty()) {
            return null;
        } else {
            return mActivityStack.get(mActivityStack.size() - 1);
        }
    }



    /**
     * 结束所有的Activity，退出应用
     */
    public static void removeAllActivity() {
        if (mActivityStack != null && mActivityStack.size() > 0) {
            for (BaseActivity activity : mActivityStack) {
                activity.finish();
            }
        }
    }

}
